package Demo52;

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
class Solution {
    /**
     * 移动链表元素删除
     * https://leetcode.cn/problems/remove-linked-list-elements/
     * @return
     */
    public ListNode removeElements1(ListNode head, int val) {
        ListNode newHead = new ListNode(0);
        newHead.next = head;
        ListNode cur = newHead;

        while(cur.next != null) {
            if(cur.next.val == val) {
                cur.next = cur.next.next;
            }else {
                cur = cur.next;
            }
        }
        return newHead.next;
    }
    public boolean hasCycle(ListNode head) {
        if(head == null) {
            return false;
        }
        ListNode fast = head,slow = head;
        fast = fast.next.next;
        while(fast.next != null) {
            if(fast == slow) {
                return true;
            }else {
                return false;
            }
        }
        return false;
    }
}
class Demo {
    public static void main(String[] args) {
//        Solution solution = new Solution();
//        ListNode head = new ListNode(3);
//        ListNode cur = head;
//        int[] arr = new int[] {2,0,-4};
//        for (int n : arr) {
//            cur.next = new ListNode(n);
//            cur = cur.next;
//        }
//        cur.next = head.next;
//        ListNode ret = solution.removeElements(head);
//        System.out.println(ret.val);
    }
}